package com.woniu.springbootshiro.mapper;

import com.woniu.springbootshiro.pojo.Role;
import com.woniu.springbootshiro.pojo.User;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.mapping.FetchType;

import java.util.List;

@Mapper
public interface UserMapper extends tk.mybatis.mapper.common.Mapper<User> {

    @Select("select * from sys_user where user_id=#{userId}")
    @Results(
            {
                    @Result(id=true,column = "user_id",property = "userId"),
                    @Result(column = "user_name",property = "userName"),
                    @Result(column = "full_name",property = "fullName"),
                    @Result(column = "password",property = "password"),
                    @Result(column = "salt",property = "salt"),
                    @Result(column="user_id",property = "roleList",javaType= List.class,many = @Many(select="com.woniu.springbootshiro.mapper.RoleMapper.selectRoleListByUserId",fetchType= FetchType.EAGER))
            }
    )
    User selectUserByIdWithRoles(@Param("userId") Long userId);

    @Select("select * from sys_user where user_name=#{username}")
    User findByUserName(@Param("username") String username);
}
